﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using SimpComm;

namespace DAL.Enums
{

    #region 企业基本类型
    /// <summary>
    /// 企业基本类型
    /// </summary>
    public class emUser_State : MyEnum<byte>
    {
        public static readonly emUser_State All = new emUser_State(255, "所有状态");
        public static readonly emUser_State NotCoop = new emUser_State(0, "正常求职者");
        public static readonly emUser_State WaitCheck = new emUser_State(1, "限制言论");
        public static readonly emUser_State IsCoop = new emUser_State(9, "黑名单");

        /// <summary>
        /// 自动生成List
        /// </summary>
        private static List<emUser_State> _Items;
        public static List<emUser_State> Items
        {
            get
            {
                if (_Items == null)
                {
                    var _Type = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType;
                    _Items =
                        _Type.GetFields().Where(field => field.FieldType == _Type).Select(
                            field => (emUser_State)field.GetValue(null)).ToList();
                }
                return _Items;
            }
        }
        public static JsonResult Get_JsonResult
        {
            get { return new JsonResult() { Data = Items, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; }
        }

        public static List<MyEnum<byte>> BaseItems
        {
            get
            {
                if (_Items == null)
                {
                    var _Type = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType;
                    _Items =
                        _Type.GetFields().Where(field => field.FieldType == _Type).Select(
                            field => (emUser_State)field.GetValue(null)).ToList();
                }
                return _Items.Select(p => p as MyEnum<byte>).ToList();
            }
        }
        public static emUser_State Get(byte value)
        {
            return Items.SingleOrDefault(p => p.Value == value);
        }

        public static emUser_State Get(string text)
        {
            var data = Items.SingleOrDefault(p => p.Text == text);
            if (data != null)
            {
                return data;
            }
            else
            {
                var i = Commons.ConvertHelper.ObjToIntNull(text);
                if (i.HasValue)
                    return Get((byte)i.Value);
            }
            return null;
        }

        //私有构造函数,有效阻止在类型外部生成实例
        private emUser_State(byte value, string text)
        {
            _Value = value;
            _Text = text;
        }
    }
    #endregion


    #region 管理员日记
    /// <summary>
    /// 日记信息类型
    /// </summary>
    public class emUserLogAction : MyEnum<byte>
    {
        public static readonly emUserLogAction All = new emUserLogAction(254, "所有日记信息");
        public static readonly emUserLogAction LoginIn = new emUserLogAction(1, "登录");

        /// <summary>
        /// 自动生成List
        /// </summary>
        private static List<emUserLogAction> _Items;
        public static List<emUserLogAction> Items
        {
            get
            {
                if (_Items == null)
                {
                    var _Type = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType;
                    _Items =
                        _Type.GetFields().Where(field => field.FieldType == _Type).Select(
                            field => (emUserLogAction)field.GetValue(null)).ToList();
                }
                return _Items;
            }
        }

        public static emUserLogAction Get(byte type)
        {
            return Items.SingleOrDefault(p => p.Value == type);
        }

        public static emUserLogAction Get(string descript)
        {
            return Items.SingleOrDefault(p => p.Text == descript);
        }

        //私有构造函数,有效阻止在类型外部生成实例
        private emUserLogAction(byte value, string text)
        {
            _Value = value;
            _Text = text;
        }

    }
    #endregion
}
